//
//  FriendListCell.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/5.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "FriendListCell.h"

@interface FriendListCell()

@property (nonatomic, strong) UIImageView *avatar_image_view;
@property (nonatomic, strong) UILabel *username_label;
@property (nonatomic, strong) UILabel *flower_num_label;
@property (nonatomic, strong) UILabel *gift_num_label;
@property (nonatomic, strong) UIButton *more_button;

@end

@implementation FriendListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self makeFriendListCellUI];
        
        
    }
    return self;
}

- (void)makeFriendListCellUI
{
    _avatar_image_view = [UIImageView new];
    _avatar_image_view.layer.masksToBounds = YES;
    _avatar_image_view.layer.cornerRadius = 18;
    [self.contentView addSubview:_avatar_image_view];
    [_avatar_image_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.bottom.mas_equalTo(-6);
        make.left.mas_equalTo(22);
        make.width.mas_equalTo(36);
    }];
    
    CGFloat labelWidth = (SCREEN_WIDTH - 120) / 3;
    
    _username_label = [UILabel new];
    _username_label.textColor = [UIColor blackColor];
    _username_label.font = [UIFont systemFontOfSize:17.0f];
    [self.contentView addSubview:_username_label];
    [_username_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(_avatar_image_view.mas_right).mas_offset(22);
        make.width.mas_equalTo(labelWidth);
    }];
    
    _flower_num_label = [UILabel new];
    _flower_num_label.textColor = [UIColor blackColor];
    _flower_num_label.font = [UIFont systemFontOfSize:17.0f];
    [self.contentView addSubview:_flower_num_label];
    [_flower_num_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(_username_label.mas_right).mas_offset(0);
        make.width.mas_equalTo(labelWidth - 30);
    }];
    
    _gift_num_label = [UILabel new];
    _gift_num_label.textColor = [UIColor blackColor];
    _gift_num_label.font = [UIFont systemFontOfSize:17.0f];
    [self.contentView addSubview:_gift_num_label];
    [_gift_num_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(_flower_num_label.mas_right).mas_offset(0);
        make.width.mas_equalTo(labelWidth - 30);
    }];
    
    _more_button = [UIButton new];
    [_more_button setImage:[UIImage imageNamed:@"friend_list_more_button"] forState:UIControlStateNormal];
    [_more_button addTarget:self action:@selector(clickMoreButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_more_button];
    [_more_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(48, 48));
        make.left.mas_equalTo(_gift_num_label.mas_right).mas_offset(0);
    }];
}

- (void)loadFriendListCellData:(FriendModel *)data
{
    [_avatar_image_view sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseIp,data.friendInfo.avatar]] placeholderImage:nil];
    
    _username_label.text = data.remarks;
    
    _gift_num_label.text = [NSString stringWithFormat:@"%ld  份",(long)data.friendInfo.gifts];
    
    _flower_num_label.text = [NSString stringWithFormat:@"%ld  朵",(long)data.friendInfo.flowers];
    
}

- (void)clickMoreButton:(UIButton *)button
{
    self.moreBlock();
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
